package leetcode.day;

import java.util.Arrays;
import java.util.List;

// 539. 最小时间差
public class FindMinDifference {
    public static void main(String[] args) {

    }

    public int findMinDifference(List<String> timePoints) {
        int n = timePoints.size();
        int[] ans = new int[n * 2];
        int index = 0;

        for (int i = 0; i < n; i++) {
            String[] split = timePoints.get(i).split(":");
            ans[index] = Integer.parseInt(split[0]) * 60 +
                    Integer.parseInt(split[1]);
            ans[index + 1] = ans[index] + 1440;
            index += 2;
        }
        Arrays.sort(ans);
        int res = ans[1] - ans[0];
        for (int i = 1; i < ans.length; i++) {
            res = Math.min(res, ans[i]-ans[i-1]);
        }
        return res;
    }
}
